home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / misc / CWeb31p9b_locale.lha / CWeb / Examples / wmerge.ch < prev    next >
Encoding:
Text File  |  1993-12-06  |  14.0 KB  |  422 lines

  1.                                 -*-Web-*-
  2. This file, WMERGE.CH, is part of CWEB.
  3. It is a changefile for WMERGE.W, Version 3.1.
  4.  
  5. Authors and Contributors:
  6. (H2B) Hans-Hermann Bode, Universität Osnabrück,
  7.   (hhbode@@dosuni1.rz.uni-osnabrueck.de or HHBODE@@DOSUNI1.BITNET).
  8.  
  9. (KG) Klaus Guntermann, TH Darmstadt,
  10.   (guntermann@@iti.informatik.th-darmstadt.de).
  11.  
  12. (AS) Andreas Scherer,
  13.   Abt-Wolf-Straße 17, 96215 Lichtenfels, Germany.
  14.  
  15. Caveat utilitor:  Some of the source code introduced by this change file is
  16. made conditional to the use of specific compilers on specific systems.
  17. This applies to places marked with `#ifdef __TURBOC__' and `#ifdef _AMIGA'.
  18.  
  19. This program is distributed WITHOUT ANY WARRANTY, express or implied.
  20.  
  21. The following copyright notice extends to this changefile only, not to
  22. the masterfile WMERGE.W.
  23.  
  24. Copyright (C) 1993 Andreas Scherer
  25. Copyright (C) 1991-1993 Hans-Hermann Bode
  26.  
  27. Permission is granted to make and distribute verbatim copies of this
  28. document provided that the copyright notice and this permission notice
  29. are preserved on all copies.
  30.  
  31. Permission is granted to copy and distribute modified versions of this
  32. document under the conditions for verbatim copying, provided that the
  33. entire resulting derived work is distributed under the terms of a
  34. permission notice identical to this one.
  35.  
  36. Version history:
  37.  
  38. Version    Date        Author    Comment
  39. p2    13 Feb 1992    H2B    First hack.
  40. p3    16 Apr 1992    H2B    Change of |@@i| allowed, /dev/null in case
  41.                 replaced by nul.
  42. p4    21 Jun 1992    H2B    Nothing changed.
  43. p5    21 Jul 1992    H2B    Nothing changed.
  44. p5a    30 Jul 1992    KG    remove one #include <stdio.h>,
  45.                 use strchr instead of index and
  46.                 include <string.h> for |strchr| declaration
  47. p5b    06 Aug 1992    KG    fixed a typo
  48. p6    06 Sep 1992    H2B    Nothing changed.
  49. p6a     15 Mar 1993     AS      SAS/C 6.0 support
  50. p6b     28 Jul 1993     AS      make some functions return `void'
  51. p6c    04 Sep 1993    AS    path searching with CWEBINCLUDE
  52. p7    09 Oct 1993    AS    Updated to CWEB 2.8
  53. p8a    11 Mar 1993    H2B    Converted to master change file.
  54.                 [Not released.]
  55. p8b    15 Apr 1993    H2B    Updated for wmerge.w 3.0beta (?).
  56.                 [Not released.]
  57. p8c    22 Jun 1993    H2B    Updated for final wmerge.w 3.0 (?).
  58. p8d    26 Oct 1993    AS    Incorporated with Amiga version 2.8 [p7].
  59. p8e    04 Nov 1993    AS    New patch level in accordance with CWEB.
  60. p9    18 Nov 1993    AS    Update for wmerge.w 3.1.
  61.     26 Nov 1993    AS    Minor casting problems fixed.
  62. ------------------------------------------------------------------------------
  63. @x l.14
  64. #include <stdio.h>
  65. @y
  66. #include <stdio.h>
  67. #include <string.h>
  68. @z
  69. ------------------------------------------------------------------------------
  70. @x l.45
  71. @<Predecl...@>=
  72. extern int strlen(); /* length of string */
  73. extern char* strcpy(); /* copy one string to another */
  74. extern int strncmp(); /* compare up to $n$ string characters */
  75. extern char* strncpy(); /* copy up to $n$ string characters */
  76. @y
  77. @z
  78. ------------------------------------------------------------------------------
  79. @x l.94
  80. input_ln(fp) /* copies a line into |buffer| or returns 0 */
  81. FILE *fp; /* what file to read from */
  82. @y
  83. int input_ln(FILE *fp) /* copies a line into |buffer| or returns 0 */
  84.   /* |fp|: what file to read from */
  85. @z
  86. ------------------------------------------------------------------------------
  87. AmigaDOS allows path names with up to 255 characters.
  88. @x l.127
  89. @d max_file_name_length 60
  90. @y
  91. @d max_file_name_length 256
  92. @z
  93. ------------------------------------------------------------------------------
  94. The third argument of `strncpy' should be of type `size_t' not `long'.
  95. @x l.157
  96. @d lines_dont_match (change_limit-change_buffer != limit-buffer ||
  97.   strncmp(buffer, change_buffer, limit-buffer))
  98. @y
  99. @d lines_dont_match (change_limit-change_buffer != limit-buffer ||
  100.   strncmp(buffer, change_buffer, (size_t)(limit-buffer)))
  101. @z
  102. ------------------------------------------------------------------------------
  103. To avoid some nasty warnings by strict ANSI C compilers we redeclare all
  104. functions to `void' that return no concrete values.
  105. @x l.172
  106. void
  107. prime_the_change_buffer()
  108. @y
  109. void prime_the_change_buffer(void)
  110. @z
  111. ------------------------------------------------------------------------------
  112. The third argument of `strncpy' should be of type `size_t' not `long'.
  113. @x l.215
  114.   strncpy(change_buffer,buffer,limit-buffer+1);
  115. @y
  116.   strncpy(change_buffer,buffer,(size_t)(limit-buffer+1));
  117. @z
  118. ------------------------------------------------------------------------------
  119. Another `void' function, i.e., a procedure.
  120. @x l.231
  121. void
  122. check_change() /* switches to |change_file| if the buffers match */
  123. @y
  124. void check_change(void) /* switches to |change_file| if the buffers match */
  125. @z
  126. ------------------------------------------------------------------------------
  127. Another `void function, i.e., a procedure.
  128. @x l.283
  129. void
  130. reset_input()
  131. @y
  132. void reset_input(void)
  133. @z
  134. ------------------------------------------------------------------------------
  135. SAS/C defines `putchar' as a macro and reports a warning about multiple
  136. macro expansion.  The resulting `wmerge' is definitely wrong; it leaves
  137. every second letter out.
  138. @x l.345
  139. void put_line()
  140. {
  141.   char *ptr=buffer;
  142.   while (ptr<limit) putc(*ptr++,out_file);
  143.   putc('\n',out_file);
  144. }
  145. @y
  146. void put_line(void)
  147. {
  148.   char *ptr=buffer;
  149.   while (ptr<limit)
  150.   {
  151.     putc(*ptr,out_file);
  152.     *ptr++;
  153.   }
  154.   putc('\n',out_file);
  155. }
  156. @z
  157. ------------------------------------------------------------------------------
  158. @x l.352
  159. @ When an \.{@@i} line is found in the |cur_file|, we must temporarily
  160. stop reading it and start reading from the named include file.  The
  161. \.{@@i} line should give a complete file name with or without
  162. double quotes.
  163. If the environment variable \.{CWEBINPUTS} is set, or if the compiler flag 
  164. of the same name was defined at compile time,
  165. \.{CWEB} will look for include files in the directory thus named, if
  166. it cannot find them in the current directory.
  167. (Colon-separated paths are not supported.)
  168. The remainder of the \.{@@i} line after the file name is ignored.
  169. @y
  170. @ When an \.{@@i} line is found in the |cur_file|, we must temporarily
  171. stop reading it and start reading from the named include file.  The
  172. \.{@@i} line should give a complete file name with or without
  173. double quotes.  The remainder of the \.{@@i} line after the file name
  174. is ignored.  \.{CWEB} will look for include files in standard directories
  175. specified in the environment variable \.{CWEBINPUTS}. Multiple search paths
  176. can be specified by delimiting them with \.{PATH\_SEPARATOR}s.  The given
  177. file is searched for in the current directory first.  You also may include
  178. device names; these must have a \.{DEVICE\_SEPARATOR} as their rightmost
  179. character.
  180.  
  181. @d PATH_SEPARATOR   ','
  182. @d DIR_SEPARATOR    '/'
  183. @d DEVICE_SEPARATOR ':'
  184. @z
  185. ------------------------------------------------------------------------------
  186. CWEB will perform a path search for `@i'nclude files along the environment
  187. variable CWEBINPUTS in case the given file can not be opened in the current
  188. directory or in the absolute path.  The single paths are delimited by
  189. PATH_SEPARATORs.
  190. @x l.380
  191.   kk=getenv("CWEBINPUTS");
  192.   if (kk!=NULL) {
  193.     if ((l=strlen(kk))>max_file_name_length-2) too_long();
  194.     strcpy(temp_file_name,kk);
  195.   }
  196.   else {
  197. #ifdef CWEBINPUTS
  198.     if ((l=strlen(CWEBINPUTS))>max_file_name_length-2) too_long();
  199.     strcpy(temp_file_name,CWEBINPUTS);
  200. #else
  201.     l=0; 
  202. #endif /* |CWEBINPUTS| */
  203.   }
  204.   if (l>0) {
  205.     if (k+l+2>=cur_file_name_end)  too_long();
  206. @.Include file name ...@>
  207.     for (; k>= cur_file_name; k--) *(k+l+1)=*k;
  208.     strcpy(cur_file_name,temp_file_name);
  209.     cur_file_name[l]='/'; /* \UNIX/ pathname separator */
  210.     if ((cur_file=fopen(cur_file_name,"r"))!=NULL) {
  211.       cur_line=0; 
  212.       goto restart; /* success */
  213.     }
  214.   }
  215. @y
  216.   if(0==set_path(include_path,getenv("CWEBINPUTS"))) {
  217.     include_depth--; goto restart; /* internal error */
  218.   }
  219.   path_prefix = include_path;
  220.   while(path_prefix) {
  221.     for(kk=temp_file_name, p=path_prefix, l=0;
  222.       p && *p && *p!=PATH_SEPARATOR;
  223.       *kk++ = *p++, l++);
  224.     if(path_prefix && *path_prefix && *path_prefix!=PATH_SEPARATOR &&
  225.       *--p!=DEVICE_SEPARATOR && *p!=DIR_SEPARATOR) {
  226.       *kk++ = DIR_SEPARATOR; l++;
  227.     }
  228.     if(k+l+2>=cur_file_name_end) too_long(); /* emergency break */
  229.     strcpy(kk,cur_file_name);
  230.     if(cur_file = fopen(temp_file_name,"r")) {
  231.       cur_line=0; goto restart; /* success */
  232.     }
  233.     if(next_path_prefix = strchr(path_prefix,PATH_SEPARATOR))
  234.       path_prefix = next_path_prefix+1;
  235.     else break; /* no more paths to search; no file found */
  236.   }
  237. @z
  238. ------------------------------------------------------------------------------
  239. Another `void' function, i.e., a procedure.
  240. @x l.450
  241. void
  242. check_complete(){
  243. @y
  244. void check_complete(void) {
  245. @z
  246. ------------------------------------------------------------------------------
  247. The third argument of `strncpy' should be of type `size_t' not `long'.
  248. @x l.453
  249.     strncpy(buffer,change_buffer,change_limit-change_buffer+1);
  250. @y
  251.     strncpy(buffer,change_buffer,(size_t)(change_limit-change_buffer+1));
  252. @z
  253. ------------------------------------------------------------------------------
  254. Another `void' function, i.e., a procedure.
  255. @x l.490
  256. @<Predecl...@>=
  257. void  err_print();
  258.  
  259. @
  260. @<Functions...@>=
  261. void
  262. err_print(s) /* prints `\..' and location of error message */
  263. char *s;
  264. @y
  265. @<Predecl...@>=
  266. void  err_print(char *);
  267.  
  268. @
  269. @<Functions...@>=
  270. void err_print(char *s) /* prints `\..' and location of error message */
  271. @z
  272. ------------------------------------------------------------------------------
  273. On the AMIGA it is very convenient to know a little bit more about the
  274. reasons why a program failed.  There are four levels of return for this
  275. purpose.  Let CWeb be so kind to use them, so scripts can be made better.
  276. @x l.540
  277. @ Some implementations may wish to pass the |history| value to the
  278. operating system so that it can be used to govern whether or not other
  279. programs are started. Here, for instance, we pass the operating system
  280. a status of 0 if and only if only harmless messages were printed.
  281. @^system dependencies@>
  282.  
  283. @<Func...@>=
  284. wrap_up() {
  285.   @<Print the job |history|@>;
  286.   if (history > harmless_message) return(1);
  287.   else return(0);
  288. }
  289. @y
  290. @ On multi-tasking systems like the Amiga it is very convenient to know
  291. a little bit more about the reasons why a program failed.  The four levels
  292. of return indicated by the |history| value are very suitable for this
  293. purpose.  Here, for instance, we pass the operating system a status of~0
  294. if and only if the run was a complete success.  Any warning or error
  295. message will result in a higher return value, so ARexx scripts can be
  296. made sensitive to these conditions.
  297. @^system dependencies@>
  298.  
  299. @d RETURN_OK     0 /* No problems, success */
  300. @d RETURN_WARN   5 /* A warning only */
  301. @d RETURN_ERROR 10 /* Something wrong */
  302. @d RETURN_FAIL  20 /* Complete or severe failure */
  303.  
  304. @<Func...@>=
  305. int wrap_up(void) {
  306.   @<Print the job |history|@>;
  307.   switch(history) {
  308.   case harmless_message: return(RETURN_WARN); break;
  309.   case error_message: return(RETURN_ERROR); break;
  310.   case fatal_message: return(RETURN_FAIL); break;
  311.   default: return(RETURN_OK);
  312.     }
  313. }
  314. @z
  315. ------------------------------------------------------------------------------
  316. @x l.569
  317. the names of those files. Most of the 128 flags are undefined but available
  318. @y
  319. the names of those files. Most of the 256 flags are undefined but available
  320. @z
  321. ------------------------------------------------------------------------------
  322. @x l.579
  323. boolean flags[128]; /* an option for each 7-bit code */
  324. @y
  325. boolean flags[256]; /* an option for each 8-bit code */
  326. @z
  327. ------------------------------------------------------------------------------
  328. @x l.593
  329. An omitted change file argument means that |'/dev/null'| should be used,
  330. @y
  331. An omitted change file argument means that |'/dev/null'| or---on {\mc
  332. MS-DOS} systems---|'nul'| or---on {\mc AMIGA} systems---|'NIL:'|
  333. should be used,
  334. @z
  335. ------------------------------------------------------------------------------
  336. Another `void' function, i.e., a procedure.
  337. @x l.599
  338. @<Pred...@>=
  339. void scan_args();
  340.  
  341. @
  342. @<Function...@>=
  343. void
  344. scan_args()
  345. @y
  346. @<Pred...@>=
  347. void scan_args(void);
  348.  
  349. @
  350. @<Function...@>=
  351. void scan_args(void)
  352. @z
  353. ------------------------------------------------------------------------------
  354. @x l.630
  355.   if (!found_change) strcpy(change_file_name,"/dev/null");
  356. @y
  357. #if defined( __TURBOC__ )
  358.   if (!found_change) strcpy(change_file_name,"nul");
  359. #elif defined( _AMIGA )
  360.   if (!found_change) strcpy(change_file_name,"NIL:");
  361. #else
  362.   if (!found_change) strcpy(change_file_name,"/dev/null");
  363. #endif
  364. @z
  365. ------------------------------------------------------------------------------
  366. @x l.612
  367. @* Index.
  368. @y
  369. @* Path searching.  On default, CTangle and CWeave are looking for include
  370. files along the path |CWEBINPUTS| given in this source file.  By setting
  371. the environment variable of the same name to a different search path that
  372. suits your personal needs, you may override the default on startup.  The
  373. following procdure copies the value of the environment variable (if any) to
  374. the variable |include_path| used for path searching.
  375.  
  376. @<Functions@>=
  377. static boolean set_path(char *ptr,char *override)
  378. {
  379.   if(override) {
  380.     if(strlen(override) >= MAXPATHLENGTH) {
  381.       err_print("! Include path too long"); return(0);
  382. @.Include path too long@>
  383.     }
  384.     else strcpy(ptr, override);
  385.   }
  386.   return(1);
  387. }
  388.  
  389. @ The path search algorithm defined in section |@<Try to open...@>|
  390. needs a few extra variables.  The search path given in the environment
  391. variable |CWEBINPUTS| must not be longer than |MAXPATHLENGTH|.  If no
  392. string is given in this variable, the internal default |CWEBINPUTS| is
  393. used instead, which holds some sensible paths.
  394.  
  395. @d MAXPATHLENGTH 4095
  396. @d CWEBINPUTS ",CWeb:,CWeb:include,CWeb:inputs"
  397.  
  398. @<Definitions...@>=
  399. char include_path[MAXPATHLENGTH+1]=CWEBINPUTS;@/
  400. char *p, *path_prefix, *next_path_prefix;@/
  401.  
  402. @ To satisfy all the {\mc ANSI} compilers out there, here are the
  403. prototypes of all internal functions.
  404.  
  405. @<Predecl...@>=
  406. int get_line(void);@/
  407. int input_ln(FILE *fp);@/
  408. int main(int argc,char **argv);
  409. int wrap_up(void);@/
  410. void check_change(void);@/
  411. void check_complete(void);@/
  412. void err_print(char *s);@/
  413. void prime_the_change_buffer(void);@/
  414. void put_line(void);@/
  415. void reset_input(void);@/
  416. void scan_args(void);@/
  417. static boolean set_path(char *ptr,char *override);@/
  418.  
  419. @* Index.
  420. @z
  421. ------------------------------------------------------------------------------
  422.